MongoDB迁移备份还原小坑

您所在的位置:网站首页 mongodbrestore 恢复表 MongoDB迁移备份还原小坑

MongoDB迁移备份还原小坑

2023-09-10 23:49| 来源: 网络整理| 查看: 265

执行备份库 mongodump --db 库名称 --out 备份存放路径 执行恢复库 mongorestore --db 库名称 备份存放路径 实例 导出数据 mongodump --host 192.168.1.1 --port 27020 --username root --password mypwd --authenticationDatabase admin --db user-data --out /home/user-data 导入数据 mongorestore --host 192.168.2.2 --port 27019 --username root --password mypwd --authenticationDatabase admin --db user-data --dir /home/user-data 报错 2021-10-11T18:42:28.495+0800 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead 2021-10-11T18:42:28.496+0800 building a list of collections to restore from /home/user-data dir 2021-10-11T18:42:28.496+0800 don't know what to do with subdirectory "user-data/user-data", skipping... 2021-10-11T18:42:28.496+0800 done 原因

导出数据时,参数 –out /home/user-data 是父文件夹的名字, 实际导出的文件在 /home/user-data/user-data之中, 所以导入时,参数应为 –dir /home/user-data/user-data。

总结 mongodump中参数 –out 是父文件夹名mongorestore中参数 –dir 需要指定到数据库文件夹数据的备份消耗的时间,小于数据的恢复时间。数据恢复时需要对数据重新建立索引。恢复的数据库占用的磁盘可能更小,因为在数据库层面,表中删除的数据,其物理文件并未删除,只是查询时不可见。备份时不会备份这些文件。刚恢复的数据库查询效率较低,因为数据未加载入缓存。


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3